﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;
using Ewts.Code;
using DataLib.Accounts.Bus;
using DataLib.Common;

namespace Ewts.RDLC
{
    public partial class ProductionStorageItemsQuery : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["UserInfo"] == null)
                {

                    Response.Redirect("/Accounts/Login.aspx");
                    return;
                }

                //参数为LoadNumID
                ListItem item = new ListItem();
                item.Text = "--请选择--";
                item.Value = "";
                DataLib.BLL.City bllLib = new DataLib.BLL.City();

                // 处理地
                dropGcity.DataSource = bllLib.GetList(" flag1 ='02'");
                dropGcity.DataTextField = "cityname";
                dropGcity.DataValueField = "cityname";
                dropGcity.DataBind();
                dropGcity.Items.Insert(0, item);


                // 归属地
                dropBcity.DataSource = bllLib.GetList(" flag1 ='01'");
                dropBcity.DataTextField = "cityname";
                dropBcity.DataValueField = "cityname";
                dropBcity.DataBind();
                dropBcity.Items.Insert(0, item);


                User curUser = new DataLib.Accounts.Bus.User();
                curUser = (User)Session["UserInfo"];
                if (curUser.UserType != "AD")
                {
                    dropGcity.SelectedValue = curUser.CompanyCity;
                    dropGcity.Enabled = false;
                }
                else
                {
                    dropGcity.SelectedValue = "全部";
                }
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {

            bindData();

        }

        public void bindData()
        {
            string bcity = dropBcity.SelectedValue;
            string gcity = dropGcity.SelectedValue;
            string enddate = txtDate.Text;

            //2015年4月16日 21:52:04  FIFA
            string error = ConfirmDate();
            if (error != "")
            {
                DataLib.Common.MessageBox.Show(Page, error);
            }
            else
            {
                //2015年4月16日 21:52:04  FIFA 把这部分放到移动到这个位置,原来在else外面
                DateTime etime = new DateTime();
                etime = DateTime.Parse(enddate);
                etime = etime.AddHours(double.Parse(txtHour.Text.Trim()));
                etime = etime.AddMinutes(double.Parse(txtMinute.Text.Trim()));
                etime = etime.AddSeconds(double.Parse(txtSecond.Text.Trim()));
                enddate = etime.ToString();
                /////////////////////////////////////////////////////////////////////

                DataTable dt = new DataTable();

                DataLib.BLL.Productions bll = new DataLib.BLL.Productions();
                dt = bll.StorageItemsQuery(enddate, bcity, gcity);
                ReportDataSource rds = new ReportDataSource("DataSet1", dt);
                ReportViewer1.LocalReport.DataSources.Clear();
                new RDLCPrinter().FillRow(dt, 3, 20, 20);//为列表添加空行
                ReportViewer1.LocalReport.DataSources.Add(rds);
                ReportViewer1.LocalReport.Refresh();
            }
        }


        /// <summary>
        /// 验证日期
        /// </summary>
        /// <returns>提示</returns>
        protected string ConfirmDate()
        {
            string strErr = "";
            if (!PageValidate.IsDateTime(txtDate.Text))
            {
                strErr += "请输入正确的查询日期 \\n";
            }
            if (!PageValidate.IsNumber(txtHour.Text))
            {
                strErr += "请输入正确的小时数字\\n";
            }
            if (!PageValidate.IsNumber(txtMinute.Text))
            {
                strErr += "请输入正确的分钟数字\\n";
            }
            if (!PageValidate.IsNumber(txtSecond.Text))
            {
                strErr += "请输入正确的秒数\\n";
            }



            return strErr;
        }
    }
}